<?php
	/**
 	 * html generator for the application
 	 */
	class HtmlxHelper extends HtmlHelper
	{
	    /**
		 * Generates title for the page
		 *
		 * @param string $text the text to display
		 * @param string $image image to display
		*/		
		public function MenuText($text, $image)
		{
			echo "<table class = 'menutext'><tr>";
			if (isset($image))
			{
				echo "<td width = 30px>";
					$this->img($image, 32, 32, $text); 
				echo "</td>";
			}
			echo "<td class = 'menutext'>".$text."</td></tr></table>";
		}
		
		/**
		 * Generates table row with the input text field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input text field name
		 * @param string $input_value input text field value
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $comment comment
		 * @param string $tr_html_attributes html attributes for the tr tag
		*/		
		public function InputTextRow($label, $input_name, $input_value, $input_html_attributes=null, $comment=null, $tr_html_attributes='')
		{	
			//generates html
			echo "
			  <tr $tr_html_attributes>
			    <td class='label'>".ucfirst($label)."</td>
			    <td>";
					$this->inputText($input_name, $input_value, 'id = "'.$input_name.'" class="text"'.$input_html_attributes);
					echo " <span class='comment'>$comment</span>
			    </td>
			  </tr>
			";			
		}

	    /**
		 * Generates table row with the combobox
		 *
		 * @param string $label label for the row
		 * @param string $combo_name combobox name
		 * @param array $value_array options array for the combobox 
		 * @param integer $selected selected option value
		 * @param string $input_html_attributes html_attributes for the combobox field
		 * @param string $tr_html_attributes html attributes for the tr tag
		 * @param boolean $check_permissions defines whether to check column permissions or not
		 * @param string $comment comment
		*/		
		public function ComboBoxRow($label, $combo_name, $value_array, $selected, $input_html_attributes=null, $tr_html_attributes=null, $check_permissions = 0, $comment = null)
		{
			//generates html
			echo "
			  <tr $tr_html_attributes>
			    <td class='label'>".ucfirst($label)."</td>
			    <td>";
					$this->combo($combo_name, $value_array, $selected, "$input_html_attributes class='combobox'");
					echo " <span class='comment'>$comment</span>   
			    </td>
			    <td class='error' width='150px'><span style='color: red'>$input_error</span></td>
			  </tr>
			";			
		}

	    /**
		 * Generates table row with the selectbox
		 *
		 * @param string $label label for the row
		 * @param string $combo_name combobox name
		 * @param array $value_array options array for the combobox 
		 * @param integer $selected selected option value
		 * @param string $input_html_attributes html_attributes for the combobox field
		 * @param boolean $check_permissions defines whether to check column permissions or not
		*/		
		public function SelectBoxRow($label, $combo_name, $value_array, $selected, $input_html_attributes=null, $check_permissions = 0)
		{
			echo "
			  <tr>
			    <td class='label'>".ucfirst($label)."</td>
			    <td>";
					$this->select($combo_name, $value_array, $selected, "class='combobox' $input_html_attributes");
					echo " <span class='comment'>$comment</span>   
			    </td>
			    <td class='error' width='150px'><span style='color: red'>$input_error</span></td>
			  </tr>
			";			
		}
		
	    /**
		 * Generates table row with the checkbox input field
		 *
		 * @param string $label label for the row
		 * @param string $input_name input field name
		 * @param boolean $is_checked indicates whether the element should be checked 
		 * @param string $input_html_attributes html_attributes for the input field
		 * @param string $tr_html_attributes html attributes for the tr tag
		 * @param string $input_value checkbox value
		 */			
		public function CheckboxRow($label, $input_name, $is_checked, $input_html_attributes=null, $input_value='1', $tr_html_attributes='')
		{
			echo "
			  <tr $tr_html_attributes>
			    <td class='label' colspan='3'>";
					$this->checkbox($input_name, $input_value, $is_checked, "class=checkbox $input_html_attributes");
					echo " ".$label."    
			    </td>
			  </tr>
			";			
		}		

	    /**
		 * Generates table row with the textarea
		 *
		 * @param string $label label for the row
		 * @param string $textarea_name textarea name
		 * @param text $textarea_value textarea value
		 * @param string $input_html_attributes html_attributes for the textarea field
		 * @param string $comment comment
		*/			
		public function TextareaRow($label, $textarea_name, $textarea_value, $input_html_attributes=null, $comment=null)
		{
			echo "
			  <tr>
			    <td valign = 'top' class='label'>".ucfirst($label)."</td>
			    <td valign = 'top' style='vertical-align: top;'>";
				
				$this->Textarea($textarea_name, $textarea_value, $input_html_attributes." class = 'textarea'", $is_rich_textarea);
				
				echo " <span class='comment'>$comment</span>
					";
					echo"
				</td>
			    <td class='error'>$input_error</td>
			  </tr>
			";		
		}
		
	    /**
		 * Generates table with submit and cancel buttons
		 *
		 * @param string $sumbit_name submit button name
		 * @param string $cancel_url url for the redirection when the cancel button is pressed
		 */			
		public function SubmitTable($sumbit_name, $cancel_url, $submit_constant = LANG_SUBMIT, $cancel_constant = LANG_CANCEL)
		{
			echo "
			  <table class = 'submitTable' border='0' cellspacing='0' cellpadding='1'>
			       <tr>
			       <td></td>
			            <td class = 'submitTable'>";
			$this->submit($sumbit_name, $submit_constant, 'class=submit');
		    echo "          
		            </td>
		            <td class = 'submitTable'>";
		    if (strstr($cancel_url, 'http://')) $this->cancel($cancel_url, $cancel_constant, 'class=cancel');
		    else $this->cancel('/spanel/'.$cancel_url, $cancel_constant, 'class=cancel');
		    echo "
		            </td>
		        </tr>
		     </table>
		    "; 
		}
		
	    /**
		 * Generates header for the table
		 *
		 * @param string $text the text to display
  		 * @param integer $colspan number of columns to be joined
		*/		
		public function TableHeaderRow($text, $colspan = 3)
		{
		   	echo " 
		  	  <tr class='header'>
		  	  	<td class='header' colspan='$colspan'>".ucfirst($text)."</td>
		  	  </tr>";		 
		}
		
		/**
		 * Displays highlighted file
		 *
		 * @param string $filename name of the file to display
		 */
		public function DisplayHighlightedFile($filename)
		{
			$source = highlight_file($filename, true);
			$explodedSource = explode("<br />", $source);
			
			$this->TableOpen('class = "source" cellspacing = "0" cellpadding="0"');
			
				foreach ($explodedSource as $key=>$value)
				{
					echo "<tr>";
						echo "<td class = 'source_number'>".($key+1)."<td>";
						echo "<td class = 'source'>".$value."<td>";
					echo "<tr>";
				}
			$this->TableClose('');
		}		

		/**
		 * Displays highlighted string
		 *
		 * @param string $string string to be parsed and displayed
  		 * @param boolean $display_numbers defines whether to add string numbers or not
		 */
		public function DisplayHighlightedString($string, $display_numbers = true)
		{
			$source = highlight_string($string, true);
			$explodedSource = explode("<br />", $source);
			
			$this->TableOpen('class = "source" cellspacing = "0" cellpadding="0"');
			
				foreach ($explodedSource as $key=>$value)
				{
					echo "<tr>";
						if ($display_numbers) echo "<td class = 'source_number'>".($key+1)."<td>";
						echo "<td class = 'source'>".$value."<td>";
					echo "<tr>";
				}
			$this->TableClose('');
		}		

		/**
		 * Generates the specified tag for the drag and drop operation
		 *
		 * @param string $id element id
		*/		
		public function DragNDropElement($id, $tag = 'div')
		{
			$theme = $_SESSION[usertheme];
			echo "<$tag {$_SESSION[dragndrop][$theme][$id]} id = '$id' class = 'dragme' style = 'position: relative;' onmouseup = 'dragndrop(this);'>";
		}		
	}
?>